I've created a "multidimensional" JS array with a function. Within that function, the console log shows the array with all elements as I would expect it.
Outside of the function, I can still show the array in the console, but it looks different, and I can't access elements with the typical arr[0] identifiers.
Any ideas what might be going on? I need to be able to access this array globally. Please be patient with me, I'm new and green.
var thisQsetTrue = [];
var thisQsetFalse = [];
//Start getDoc
function getDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
buildArray(this);
}
xhttp.open("GET", "AddisonNovice.xml");
xhttp.send();
}
//End get Doc
//Start buildArray
function buildArray(xml) {
const xmlDoc2 = xml.responseXML;
const y = xmlDoc2.getElementsByTagName("question");
//Build the true answer array
for (let i = 0; i <y.length; i++) {
var tempArray = [];
if (y[i].getElementsByTagName("type")[0].childNodes[0].nodeValue == "true") {
tempArray.push(y[i].getElementsByTagName("query")[0].childNodes[0].nodeValue);
tempArray.push(y[i].getElementsByTagName("feedback")[0].childNodes[0].nodeValue);
thisQsetTrue.push(tempArray);
}
}
//Build the false answer array
for (let i = 0; i <y.length; i++) {
var tempArray2 = [];
if (y[i].getElementsByTagName("type")[0].childNodes[0].nodeValue == "false") {
tempArray2.push(y[i].getElementsByTagName("query")[0].childNodes[0].nodeValue);
tempArray2.push(y[i].getElementsByTagName("feedback")[0].childNodes[0].nodeValue);
thisQsetFalse.push(tempArray2);
}
}
console.log(thisQsetFalse);//Array displays normally
}
//End buildArray
//Call getDoc
getDoc();
console.log(thisQsetFalse);//Array displays differently
Console log screenshot. As you can see, all the elements of the array are there, but it looks different, and I can't get to the elements: Screenshot of console log